import { createRouter, createWebHistory } from "vue-router";
import Layout from "../layout/Layout.vue";
import store from "../store";
import Home from "../views/Home.vue";
import Search from "../views/Search.vue";
import SearchDetails from "../views/SearchDetails.vue";
import MusicDetails from "../views/popup/MusicDetails.vue";
import PlayListDetails from "../views/PlayListDetails.vue";
const routes = [
    {
        path:"/",
        component: Layout,
        children: [
            {
                path: "/",
                name:"Home",
                component: Home
            },
            {
                path:"search",
                name:"Search",
                meta:{
                    showSearch: false,
                    showTabbar: false
                },
                component: Search
            },{
                path:"search_details/:keyword",
                name:"search_details",
                props: true,
                meta:{
                    keepAlive: false,
                    // showSearch: false,
                    showTabbar: false
                },
                component: SearchDetails
            },
            {
                path: "/music",
                component: MusicDetails
            },
            {
                path: "/playlist/:playListId",
                props: true,
                meta:{
                    keepAlive: false,
                    showSearch: false,
                    showTabbar: false
                },
                component: PlayListDetails
            }
        ]
    },

];

const history = createWebHistory();

let router = createRouter({
    history,
    routes
});


/**
 * 通过判断那些页面需要隐藏底部菜单
 * @param {*} meta 
 */
function isShowTabbar(meta){
    let showTabbar = meta.showTabbar;
    if(showTabbar === false){
        store.commit("common/hideTabbar");
    }else{
        store.commit("common/showTabbar");
    }
}


/**
 * 通过判断那些页面需要隐藏搜索栏
 * @param {*} meta 
 */
function isShowSearch(meta){
    let showSearch = meta.showSearch;
    if(showSearch === false){
        store.commit("common/hideSearch");
    }else{
        store.commit("common/showSearch");
    }
}



function isShowMusicBar(){

}

router.beforeEach((to,from,next)=>{
    let meta = to.meta;
    isShowTabbar(meta);
    isShowSearch(meta);
    next();
})

export default router;